package com.cg.ggkt.vod.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cg.ggkt.domain.ResponseData;
import com.cg.ggkt.exception.GgktException;
import com.cg.ggkt.model.vod.Teacher;
import com.cg.ggkt.vod.service.ITeacherService;
import com.cg.ggkt.vo.vod.TeacherQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author caigang
 * @since 2022-07-20
 */
@Api(tags = "讲师管理接口")
@RestController
@RequestMapping("/admin/teacher")
public class TeacherController {

    @Autowired
    private ITeacherService teacherService;

    @ApiOperation("所有讲师列表")
    @GetMapping("/findAll")
    public ResponseData<List<Teacher>> findAll() throws Exception{
        List<Teacher> teachers = teacherService.list();
        return ResponseData.ok(teachers);
    }

    @ApiOperation("逻辑删除讲师")
    @DeleteMapping("/{id}")
    public ResponseData<Boolean> removeById(@PathVariable("id")Long id){
        if(teacherService.removeById(id)){
            return ResponseData.ok();
        }
        return ResponseData.fail();
    }

    @ApiOperation("条件查询分页")
    @GetMapping("/findQueryPage/{current}/{limit}")
    public ResponseData findPage(@PathVariable long current,
                                 @PathVariable long limit,
                                 @RequestBody(required = false) TeacherQueryVo vo){
        return ResponseData.ok(teacherService.findQueryPage(current, limit, vo));
    }

    @ApiOperation("添加讲师")
    @PostMapping("/saveTeacher")
    public ResponseData saveTeacher(@RequestBody Teacher teacher){
        if (teacherService.save(teacher)) {
            return ResponseData.ok();
        }
        return ResponseData.fail();
    }

    @ApiOperation("修改讲师")
    @PutMapping("/updateTeacher")
    public ResponseData updateTeacher(@RequestBody Teacher teacher){
        if(teacherService.updateById(teacher)){
            return ResponseData.ok();
        }
        return ResponseData.fail();
    }



}
